﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using XuanFe.Database.Model;

namespace XuanFe.Database.DAL
{
    public class BookingDAL
    {
        private const string SQL_SELECT_WS_BOOKING = "select BKG_BOOKING_ID as BOOKING_ID,BKG_CUSTOMER_ID as CUSTOMER_ID,BKG_CUSTOMER_NAME as CUSTOMER_NAME,BKG_MOBILE_NUMBER as MOBILE_NUMBER,BKG_TELEPHONE as TELEPHONE,BKG_EMAIL as EMAIL,BKG_BOOKING_TIME as BOOKING_TIME,BKG_BOOKING_TYPE as BOOKING_TYPE,BKG_BOOKING_STATUS as BOOKING_STATUS,BKG_PRINT_FLG as PRINT_FLG,BKG_PAID_FLG as PAID_FLG,BKG_TOTAL_AMOUNT as TOTAL_AMOUNT,BKG_TOTAL_BASE as TOTAL_BASE,BKG_TOTAL_PAID as TOTAL_PAID,BKG_CLAIM_FLG as CLAIM_FLG,BKG_CONTACT_ADDRESS as CONTACT_ADDRESS,BKG_REMARK as REMARK,BKG_SALE_STAFF_ID as SALE_STAFF_ID,BKG_SALE_TIME as SALE_TIME,BKG_PRINT_STAFF_ID as PRINT_STAFF_ID,BKG_PRINT_TIME as PRINT_TIME,BKG_COLLECTION_STAFF_ID as COLLECTION_STAFF_ID,BKG_COLLECTION_TIME as COLLECTION_TIME,BKG_RCRE_STAFF_ID as RCRE_STAFF_ID,BKG_RCRE_TIME as RCRE_TIME,BKG_LCHG_STAFF_ID as LCHG_STAFF_ID,BKG_LCHG_TIME as LCHG_TIME,(case BKG_BOOKING_TYPE when 'LOC' then '现场预订' when 'TEL' then '电话预订' when 'WEB' then '网上预订' when 'SEO' then '推广预订' else '网上预订' end) as BOOKING_TYPE_DESC,(case BKG_BOOKING_STATUS when 0 then '新建' when 10 then '未支付出票中' when 11 then '已支付出票中' when 20 then '待支付已出票' when 21 then '已支付已出票' when 30 then '已退票' when 31 then '部分退票' when 99 then '已取消' else '未知' end) as BOOKING_STATUS_DESC,(select STF_STAFF_NAME from WS_STAFF where STF_STAFF_ID=BKG_SALE_STAFF_ID) as SALE_STAFF_NAME,(select STF_STAFF_NAME from WS_STAFF where STF_STAFF_ID=BKG_PRINT_STAFF_ID) as PRINT_STAFF_NAME,(select STF_STAFF_NAME from WS_STAFF where STF_STAFF_ID=BKG_COLLECTION_STAFF_ID) as COLLECTION_STAFF_NAME,BKG_DATA as BOOKING_DATA,insert(BKG_MOBILE_NUMBER,4,4,'****') as MOBILE_NUMBER_START,BKG_PAYMENT_TYPE as PAYMENT_TYPE,BKG_PRINT_COMPANY as PRINT_COMPANY from WS_BOOKING where 1=1 ";
        private const string SQL_INSERT_WS_BOOKING = "insert into WS_BOOKING(BKG_BOOKING_ID,BKG_CUSTOMER_ID,BKG_CUSTOMER_NAME,BKG_MOBILE_NUMBER,BKG_TELEPHONE,BKG_EMAIL,BKG_BOOKING_TIME,BKG_BOOKING_TYPE,BKG_BOOKING_STATUS,BKG_PRINT_FLG,BKG_PAID_FLG,BKG_TOTAL_AMOUNT,BKG_TOTAL_BASE,BKG_TOTAL_PAID,BKG_CLAIM_FLG,BKG_CONTACT_ADDRESS,BKG_REMARK,BKG_SALE_STAFF_ID,BKG_SALE_TIME,BKG_RCRE_STAFF_ID,BKG_RCRE_TIME,BKG_DATA,BKG_PAYMENT_TYPE,BKG_PRINT_COMPANY) values(@BookingId,@CustomerId,@CustomerName,@MobileNumber,@Telephone,@EMail,@BookingTime,@BookingType,@BookingStatus,@PrintFlag,@PaidFlag,@TotalAmount,@TotalBase,@TotalPaid,@ClaimFlag,@ContactAddress,@Remark,@SaleStaffId,@SaleTime,@LastStaffId,@LastTime,@BookingData,@PaymentType,@PrintCompany)";
        private const string SQL_UPDATE_WS_BOOKING = "update WS_BOOKING set BKG_CUSTOMER_NAME=@CustomerName,BKG_MOBILE_NUMBER=@MobileNumber,BKG_TELEPHONE=@Telephone,BKG_EMAIL=@EMail,BKG_CLAIM_FLG=@ClaimFlag,BKG_CONTACT_ADDRESS=@ContactAddress,BKG_REMARK=@Remark,BKG_TOTAL_AMOUNT=@TotalAmount,BKG_TOTAL_BASE=@TotalBase,BKG_LCHG_STAFF_ID=@LastStaffId,BKG_LCHG_TIME=@LastTime,BKG_DATA=@BookingData,BKG_PAYMENT_TYPE=@PaymentType,BKG_PRINT_COMPANY=@PrintCompany where 1=1 ";

        private const string SQL_WHERE_BOOKING_ID = " and BKG_BOOKING_ID=@BookingId ";
        private const string SQL_WHERE_CUSTOMER_ID = " and BKG_CUSTOMER_ID=@CustomerId ";
        private const string SQL_WHERE_SALE_STAFF_ID = " and BKG_SALE_STAFF_ID=@SaleStaffId ";
        private const string SQL_WHERE_CUSTOMER_NAME = " and BKG_CUSTOMER_NAME=@CustomerName ";
        private const string SQL_WHERE_CUSTOMER_NAME_LIKE = " and BKG_CUSTOMER_NAME like @CustomerName ";
        private const string SQL_WHERE_MOBILE_NUMBER = " and BKG_MOBILE_NUMBER=@MobileNumber ";
        private const string SQL_WHERE_MOBILE_NUMBER_LIKE = " and BKG_MOBILE_NUMBER like @MobileNumber ";
        private const string SQL_WHERE_SALE_TIME = " and BKG_SALE_TIME between @StartSaleTime and @EndSaleTime ";

        private const string SQL_ORDER_BY_SALE_TIME_DESC = " order by SALE_TIME desc";

        private const string PARM_BOOKING_ID = "@BookingId";
        private const string PARM_CUSTOMER_ID = "@CustomerId";
        private const string PARM_CUSTOMER_NAME = "@CustomerName";
        private const string PARM_MOBILE_NUMBER = "@MobileNumber";
        private const string PARM_TELEPHONE = "@Telephone";
        private const string PARM_EMAIL = "@EMail";
        private const string PARM_BOOKING_TIME = "@BookingTime";
        private const string PARM_BOOKING_TYPE = "@BookingType";
        private const string PARM_BOOKING_STATUS = "@BookingStatus";
        private const string PARM_PRINT_FLG = "@PrintFlag";
        private const string PARM_PAID_FLG = "@PaidFlag";
        private const string PARM_TOTAL_AMOUNT = "@TotalAmount";
        private const string PARM_TOTAL_BASE = "@TotalBase";
        private const string PARM_TOTAL_PAID = "@TotalPaid";
        private const string PARM_CLAIM_FLG = "@ClaimFlag";
        private const string PARM_CONTACT_ADDRESS = "@ContactAddress";
        private const string PARM_REMARK = "@Remark";
        private const string PARM_SALE_STAFF_ID = "@SaleStaffId";
        private const string PARM_SALE_TIME = "@SaleTime";
        private const string PARM_LAST_STAFF_ID = "@LastStaffId";
        private const string PARM_LAST_TIME = "@LastTime";
        private const string PARM_START_SALE_TIME = "@StartSaleTime";
        private const string PARM_END_SALE_TIME = "@EndSaleTime";
        private const string PARM_BOOKING_DATA = @"BookingData";
        private const string PARM_PAYMENT_TYPE = @"PaymentType";
        private const string PARM_PRINT_COMPANY = @"PrintCompany";

        Nullable<DateTime> NullDateTime = null;
        private static BookingDAL instance = new BookingDAL();
        /// <summary>
        /// 初始化实例
        /// </summary>
        /// <returns></returns>
        public static BookingDAL Instance
        {
            get
            {
                return instance;
            }
        }
        public DataSet GetDataSet(QueryBookingModel model)
        {
            StringBuilder sbSQL = new StringBuilder(SQL_SELECT_WS_BOOKING);
            List<MySqlParameter> parms = new List<MySqlParameter>();

            if (model != null)
            {
                if (model.QueryCustomerId)
                {
                    sbSQL.Append(SQL_WHERE_CUSTOMER_ID);
                    parms.Add(new MySqlParameter(PARM_CUSTOMER_ID, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.CustomerId });
                }
                if (model.QuerySaleStaffId)
                {
                    sbSQL.Append(SQL_WHERE_SALE_STAFF_ID);
                    parms.Add(new MySqlParameter(PARM_SALE_STAFF_ID, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.SaleStaffId });
                }
                if (model.QueryName)
                {
                    if (model.FuzzyName)
                    {
                        sbSQL.Append(SQL_WHERE_CUSTOMER_NAME_LIKE);
                        parms.Add(new MySqlParameter(PARM_CUSTOMER_NAME, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = string.Format("%{0}%", model.Name) });
                    }
                    else
                    {
                        sbSQL.Append(SQL_WHERE_CUSTOMER_NAME);
                        parms.Add(new MySqlParameter(PARM_CUSTOMER_NAME, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Name });
                    }
                }
                if (model.QueryMobileNumber)
                {
                    if (model.FuzzyMobileNumber)
                    {
                        sbSQL.Append(SQL_WHERE_MOBILE_NUMBER_LIKE);
                        parms.Add(new MySqlParameter(PARM_MOBILE_NUMBER, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = string.Format("%{0}%", model.MobileNumber) });
                    }
                    else
                    {
                        sbSQL.Append(SQL_WHERE_MOBILE_NUMBER);
                        parms.Add(new MySqlParameter(PARM_MOBILE_NUMBER, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.MobileNumber });
                    }
                }
                if (model.QuerySaleTime)
                {
                    sbSQL.Append(SQL_WHERE_SALE_TIME);
                    parms.Add(new MySqlParameter(PARM_START_SALE_TIME, MySqlDbType.DateTime) { Direction = ParameterDirection.Input, Value = model.StartSaleTime });
                    parms.Add(new MySqlParameter(PARM_END_SALE_TIME, MySqlDbType.DateTime) { Direction = ParameterDirection.Input, Value = model.EndSaleTime });
                }
            }
            sbSQL.Append(SQL_ORDER_BY_SALE_TIME_DESC);

            return MySQLHelper.Instance.ExecuteDataSet(MySQLHelper.Instance.ConnectionString, CommandType.Text, sbSQL.ToString(), parms.ToArray());
        }
        public List<BookingModel> Gets(QueryBookingModel model)
        {
            using (DataSet ds = this.GetDataSet(model))
            {
                DataTable dt = ds.Tables[0];
                List<BookingModel> list = dt.AsEnumerable().Select(t => new BookingModel
                {
                    Id = Convert.ToString(t.ItemArray[0]),
                    CustomerId = Convert.ToString(t.ItemArray[1]),
                    CustomerName = Convert.ToString(t.ItemArray[2]),
                    MobileNumber = Convert.ToString(t.ItemArray[3]),
                    Telephone = Convert.ToString(t.ItemArray[4]),
                    EMail = Convert.ToString(t.ItemArray[5]),
                    BookingTime = Convert.ToDateTime(t.ItemArray[6]),
                    BookingType = Convert.ToString(t.ItemArray[7]),
                    BookingStatus = Convert.ToInt32(t.ItemArray[8]),
                    Printed = string.Equals(Convert.ToString(t.ItemArray[9]), "Y"),
                    Paid = string.Equals(Convert.ToString(t.ItemArray[10]), "Y"),
                    TotalAmount = Convert.ToDecimal(t.ItemArray[11]),
                    TotalBase = Convert.ToDecimal(t.ItemArray[12]),
                    TotalPaid = Convert.ToDecimal(t.ItemArray[13]),
                    Claim = string.Equals(Convert.ToString(t.ItemArray[14]), "Y"),
                    ContactAddress = Convert.ToString(t.ItemArray[15]),
                    Remark = Convert.ToString(t.ItemArray[16]),
                    SaleStaffId = Convert.ToString(t.ItemArray[17]),
                    SaleTime = Convert.ToDateTime(t.ItemArray[18]),
                    PrintStaffId = Convert.ToString(t.ItemArray[19]),
                    PrintTime = t.IsNull(20) ? this.NullDateTime : Convert.ToDateTime(t.ItemArray[20]),
                    CollectionStaffId = Convert.ToString(t.ItemArray[21]),
                    CollectionTime = t.IsNull(22) ? this.NullDateTime : Convert.ToDateTime(t.ItemArray[22]),
                    CreatedStaffId = Convert.ToString(t.ItemArray[23]),
                    CreatedDate = Convert.ToDateTime(t.ItemArray[24]),
                    LastModifiedStaffId = t.IsNull(25) ? string.Empty : Convert.ToString(t.ItemArray[25]),
                    LastModifiedDate = t.IsNull(26) ? NullDateTime : Convert.ToDateTime(t.ItemArray[26]),
                    SaleStaffName = Convert.ToString(t.ItemArray[29]),
                    PrintStaffName = t.IsNull(30) ? string.Empty : Convert.ToString(t.ItemArray[30]),
                    CollectionStaffName = t.IsNull(31) ? string.Empty : Convert.ToString(t.ItemArray[31]),
                    Data = t.IsNull(32) ? string.Empty : Convert.ToString(t.ItemArray[32]),
                    PaymentType = t.IsNull(34) ? string.Empty : Convert.ToString(t.ItemArray[34]),
                    PrintCompany = t.IsNull(35) ? string.Empty : Convert.ToString(t.ItemArray[35]),
                }).ToList<BookingModel>();

                return list;
            }
        }
        public BookingModel Get(string bookingId)
        {
            StringBuilder sbSQL = new StringBuilder(SQL_SELECT_WS_BOOKING);
            sbSQL.Append(SQL_WHERE_BOOKING_ID);

            List<MySqlParameter> parms = new List<MySqlParameter>();
            parms.Add(new MySqlParameter(PARM_BOOKING_ID, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = bookingId });

            using (DataSet ds = MySQLHelper.Instance.ExecuteDataSet(MySQLHelper.Instance.ConnectionString, CommandType.Text, sbSQL.ToString(), parms.ToArray()))
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow t = ds.Tables[0].Rows[0];
                    return new BookingModel()
                    {
                        Id = Convert.ToString(t.ItemArray[0]),
                        CustomerId = Convert.ToString(t.ItemArray[1]),
                        CustomerName = Convert.ToString(t.ItemArray[2]),
                        MobileNumber = Convert.ToString(t.ItemArray[3]),
                        Telephone = Convert.ToString(t.ItemArray[4]),
                        EMail = Convert.ToString(t.ItemArray[5]),
                        BookingTime = Convert.ToDateTime(t.ItemArray[6]),
                        BookingType = Convert.ToString(t.ItemArray[7]),
                        BookingStatus = Convert.ToInt32(t.ItemArray[8]),
                        Printed = string.Equals(Convert.ToString(t.ItemArray[9]), "Y"),
                        Paid = string.Equals(Convert.ToString(t.ItemArray[10]), "Y"),
                        TotalAmount = Convert.ToDecimal(t.ItemArray[11]),
                        TotalBase = Convert.ToDecimal(t.ItemArray[12]),
                        TotalPaid = Convert.ToDecimal(t.ItemArray[13]),
                        Claim = string.Equals(Convert.ToString(t.ItemArray[14]), "Y"),
                        ContactAddress = Convert.ToString(t.ItemArray[15]),
                        Remark = Convert.ToString(t.ItemArray[16]),
                        SaleStaffId = Convert.ToString(t.ItemArray[17]),
                        SaleTime = Convert.ToDateTime(t.ItemArray[18]),
                        PrintStaffId = Convert.ToString(t.ItemArray[19]),
                        PrintTime = t.IsNull(20) ? this.NullDateTime : Convert.ToDateTime(t.ItemArray[20]),
                        CollectionStaffId = Convert.ToString(t.ItemArray[21]),
                        CollectionTime = t.IsNull(22) ? this.NullDateTime : Convert.ToDateTime(t.ItemArray[22]),
                        CreatedStaffId = Convert.ToString(t.ItemArray[23]),
                        CreatedDate = Convert.ToDateTime(t.ItemArray[24]),
                        LastModifiedStaffId = t.IsNull(25) ? string.Empty : Convert.ToString(t.ItemArray[25]),
                        LastModifiedDate = t.IsNull(26) ? NullDateTime : Convert.ToDateTime(t.ItemArray[26]),
                        SaleStaffName = Convert.ToString(t.ItemArray[29]),
                        PrintStaffName = t.IsNull(30) ? string.Empty : Convert.ToString(t.ItemArray[30]),
                        CollectionStaffName = t.IsNull(31) ? string.Empty : Convert.ToString(t.ItemArray[31]),
                        Data = t.IsNull(32) ? string.Empty : Convert.ToString(t.ItemArray[32]),
                        PaymentType = t.IsNull(34) ? string.Empty : Convert.ToString(t.ItemArray[34]),
                        PrintCompany = t.IsNull(35) ? string.Empty : Convert.ToString(t.ItemArray[35]),
                    };
                }
                return null;
            }
        }
        public int Insert(DbTransaction trans, BookingModel model)
        {
            List<MySqlParameter> parms = new List<MySqlParameter>();
            parms.Add(new MySqlParameter(PARM_BOOKING_ID, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Id });
            parms.Add(new MySqlParameter(PARM_CUSTOMER_ID, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.CustomerId });
            parms.Add(new MySqlParameter(PARM_CUSTOMER_NAME, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.CustomerName });
            parms.Add(new MySqlParameter(PARM_MOBILE_NUMBER, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.MobileNumber });
            parms.Add(new MySqlParameter(PARM_TELEPHONE, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Telephone });
            parms.Add(new MySqlParameter(PARM_EMAIL, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.EMail });
            parms.Add(new MySqlParameter(PARM_BOOKING_TIME, MySqlDbType.DateTime) { Direction = ParameterDirection.Input, Value = model.BookingTime });
            parms.Add(new MySqlParameter(PARM_BOOKING_TYPE, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.BookingType });
            parms.Add(new MySqlParameter(PARM_BOOKING_STATUS, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.BookingStatus });
            parms.Add(new MySqlParameter(PARM_PRINT_FLG, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Printed ? "Y" : "N" });
            parms.Add(new MySqlParameter(PARM_PAID_FLG, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Paid ? "Y" : "N" });
            parms.Add(new MySqlParameter(PARM_TOTAL_AMOUNT, MySqlDbType.Decimal) { Direction = ParameterDirection.Input, Value = model.TotalAmount });
            parms.Add(new MySqlParameter(PARM_TOTAL_BASE, MySqlDbType.Decimal) { Direction = ParameterDirection.Input, Value = model.TotalBase });
            parms.Add(new MySqlParameter(PARM_TOTAL_PAID, MySqlDbType.Decimal) { Direction = ParameterDirection.Input, Value = model.TotalPaid });
            parms.Add(new MySqlParameter(PARM_CLAIM_FLG, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Claim ? "Y" : "N" });
            parms.Add(new MySqlParameter(PARM_CONTACT_ADDRESS, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.ContactAddress });
            parms.Add(new MySqlParameter(PARM_REMARK, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Remark });
            parms.Add(new MySqlParameter(PARM_SALE_STAFF_ID, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.SaleStaffId });
            parms.Add(new MySqlParameter(PARM_SALE_TIME, MySqlDbType.DateTime) { Direction = ParameterDirection.Input, Value = model.SaleTime });
            parms.Add(new MySqlParameter(PARM_LAST_STAFF_ID, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.LastModifiedStaffId });
            parms.Add(new MySqlParameter(PARM_LAST_TIME, MySqlDbType.DateTime) { Direction = ParameterDirection.Input, Value = model.LastModifiedDate });
            parms.Add(new MySqlParameter(PARM_BOOKING_DATA, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Data });
            parms.Add(new MySqlParameter(PARM_PAYMENT_TYPE, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.PaymentType });
            parms.Add(new MySqlParameter(PARM_PRINT_COMPANY, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.PrintCompany });

            return MySQLHelper.Instance.ExecuteNonQuery(trans, CommandType.Text, SQL_INSERT_WS_BOOKING, parms.ToArray());
        }
        public int Update(DbTransaction trans, BookingModel model)
        {
            StringBuilder sbSQL = new StringBuilder(SQL_UPDATE_WS_BOOKING);
            sbSQL.Append(SQL_WHERE_BOOKING_ID);

            List<MySqlParameter> parms = new List<MySqlParameter>();
            parms.Add(new MySqlParameter(PARM_BOOKING_ID, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Id });
            parms.Add(new MySqlParameter(PARM_CUSTOMER_NAME, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.CustomerName });
            parms.Add(new MySqlParameter(PARM_MOBILE_NUMBER, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.MobileNumber });
            parms.Add(new MySqlParameter(PARM_TELEPHONE, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Telephone });
            parms.Add(new MySqlParameter(PARM_EMAIL, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.EMail });
            parms.Add(new MySqlParameter(PARM_TOTAL_AMOUNT, MySqlDbType.Decimal) { Direction = ParameterDirection.Input, Value = model.TotalAmount });
            parms.Add(new MySqlParameter(PARM_TOTAL_BASE, MySqlDbType.Decimal) { Direction = ParameterDirection.Input, Value = model.TotalBase });
            parms.Add(new MySqlParameter(PARM_CLAIM_FLG, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Claim ? "Y" : "N" });
            parms.Add(new MySqlParameter(PARM_CONTACT_ADDRESS, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.ContactAddress });
            parms.Add(new MySqlParameter(PARM_REMARK, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Remark });
            parms.Add(new MySqlParameter(PARM_LAST_STAFF_ID, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.LastModifiedStaffId });
            parms.Add(new MySqlParameter(PARM_LAST_TIME, MySqlDbType.DateTime) { Direction = ParameterDirection.Input, Value = model.LastModifiedDate });
            parms.Add(new MySqlParameter(PARM_BOOKING_DATA, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.Data });
            parms.Add(new MySqlParameter(PARM_PAYMENT_TYPE, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.PaymentType });
            parms.Add(new MySqlParameter(PARM_PRINT_COMPANY, MySqlDbType.String) { Direction = ParameterDirection.Input, Value = model.PrintCompany });

            return MySQLHelper.Instance.ExecuteNonQuery(trans, CommandType.Text, sbSQL.ToString(), parms.ToArray());
        }
    }
}
